<!--
 * @Description: 问卷预览
 * @Author: liyujie
 * @Date: 2021/06/05
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/06/05
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <el-button
                    type="text"
                    @click="handleRoute('shopQuestionnaireList')"
                >
                    关闭预览
                </el-button>
            </div>
            <!-- /header -->
            <div
                class="form-wrapper"
                v-if="formData"
            >
                <div class="question-header">
                    <div class="title">{{ formData.title }}</div>
                    <div class="intro">{{ formData.intro }}</div>
                </div>
                <div class="tips-view">
                    此为预览页面，不能参与做答
                </div>
                <div class="question-form">
                    <custom-form-data :data="formData.form_config"/>
                </div>
                <div class="question-footer">
                    <el-button
                        size="medium"
                        style="width: 120px"
                        @click="handleRoute('shopQuestionnaireList')"
                    >
                        返回
                    </el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import { deepClone } from "@/assets/js/utils";
import CustomFormData from "@/components/shop-questionnaire/custom-form-data";

export default {
    name: 'ShopQuestionnairePreview',
    mixins: [back],
    components: {CustomFormData},
    data() {
        return {
            sq_no: '',
            // 预览数据
            formData: null
        };
    },
    computed: {},
    watch: {},
    filters: {},
    mounted() {
        let query = this.$route.query;

        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '商城'}, {title: '商家问卷', path: '/student/shop-questionnaire-list'}, {title: '预览问卷'}]);
        this.authResult = this.$route.meta.authResult;
        this.sq_no = query.sq_no;
        this.getDetailData();
    },

    methods: {
        /**
         * @description 获取数据
         */
        getDetailData() {
            if (this.sq_no) {
                let params = {
                    sq_no: this.sq_no
                };

                this.$post('/student/shop_questionnaire%5Cget', params, res => {
                    if (res.code === 1) {
                        this.formData = res.data;
                    } else {
                        this.$notify({
                            title: '提示',
                            message: res.msg,
                            type: 'warning'
                        });
                    }
                });
            } else {
                // 本地获取预览数据
                this.formData = JSON.parse(sessionStorage.getItem('QUESTION_CUSTOM_FORM'));
                this.formData.form_config = JSON.parse(this.formData.form_config);
            }
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;
    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;
        overflow-y: auto;
        &::-webkit-scrollbar {
            width: 6px;
        }

        /*header*/

        .header {
            height: 52px;
            padding: 0 32px;
            display: flex;
            justify-content: flex-end;
            align-items: center;
            font-size: 14px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;
            color: #20A0FF;
            flex-shrink: 0;
        }
    }
    .form-wrapper {
        .question-header {
            padding: 24px 0;
            border-bottom: 1px dashed #DCDFE6;
            .title {
                font-size: 24px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                text-align: center;
            }
            .intro {
                font-size: 14px;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #999999;
                margin-top: 24px;
                text-align: center;
                line-height: 24px;
            }
        }
        .tips-view {
            height: 48px;
            background: #FFF3E8;
            padding: 0 165px;
            display: flex;
            align-items: center;
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #F79038;
        }
        .question-form {
            padding: 32px 165px 0;
        }
        .question-footer {
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 52px;
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
    /deep/ .el-table__fixed-right {
        right: 6px!important;
    }
}
</style>
